package leetcode_day._2023._11;

/**
 * 53.最大子数组和
 * 算法: 动态规划 + 贪心
 *
 * @author yezh
 * @date 2023/11/20 9:59
 */
public class _20 {

    public int maxSubArray(int[] nums) {
        int ans = nums[0], cur = nums[0];
        for (int i = 1; i < nums.length; i++) {
            cur = Math.max(cur + nums[i], nums[i]);
            ans = Math.max(cur, ans);
        }
        return ans;
    }

}
